#ifndef FILE_TRANSFER_H
#define FILE_TRANSFER_H
#include <thread>
#include <vector>
#include <list>
#include <mutex>
#include <condition_variable>
#include "global.h"
#include "../include/SingleClass.h"
#include <memory>
#include <atomic>
#include <unordered_map>
#include <fstream>


class file_transfer_thread_item{

public:
    file_transfer_thread_item();
    //加任务接口
    void add_task(struct full_msg *);
    ~file_transfer_thread_item();
    
private:
    std::thread _thread;
    std::list<struct full_msg *> task_queue;
    std::mutex mtx;
    std::condition_variable cond_var;
    std::atomic<bool> is_running;
    //bool is_running;
    //文件映射表  hash_file_id---ofstream
    std::unordered_map<std::string,std::shared_ptr<std::ofstream>>file_map; // client_msg_uuid----ofstream
    std::unordered_map<std::string,std::shared_ptr<std::ifstream>>read_file_map;    // download_uuid----ofstream



    void doing_task(struct full_msg *);




};

class file_transfer_thread_pool:public SingleClass<file_transfer_thread_pool>{

public:
    void deal_task(struct full_msg *);
    ~file_transfer_thread_pool();
private:
    friend class SingleClass<file_transfer_thread_pool>;
    file_transfer_thread_pool();
    std::vector<std::shared_ptr<file_transfer_thread_item>> pool;
    int pool_num;


};



#endif